package A1_字符串;

public class LC_541反转字符串II_StringBuilder实现反转 {
    public static void main(String[] args){
        String str="abcd";
        StringBuilder str1=new StringBuilder(str);
        str1=str1.reverse();
        System.out.println(str1);
    }
    public String reverseStr(String s, int k) {
        for(int i=0;i<s.length();i+=2*k){
            if(i+k<=s.length()){
                StringBuilder str=new StringBuilder(s);
                String str1=str.substring(i,i+k);
                StringBuilder str2=new StringBuilder(str1);
                str2=str2.reverse();
                str=str.replace(i,i+k, String.valueOf(str2));
                s= String.valueOf(str);
                continue;
            }
            StringBuilder str=new StringBuilder(s);
            String str1=str.substring(i,s.length());
            StringBuilder str2=new StringBuilder(str1);
            str2=str2.reverse();
            str=str.replace(i,s.length(), String.valueOf(str2));
            s= String.valueOf(str);
        }
        return s;
    }
}
